﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoleMasterForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.SystemManage.RoleMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>角色管理</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    角色名称：<input id="RoleName" class="mini-textbox" emptytext="请输入角色名称" style="width: 150px;"
                        onenter="onKeyEnter" />
                    <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a> <a class="mini-button"
                        iconcls="icon-reset" onclick="reset()">重 置</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                        class="mini-button" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                    <a class="mini-button" iconcls="icon-remove" onclick="remove()" plain="true">删除</a>
                    <span class="separator"></span><a class="mini-button" onclick="close()" iconcls="icon-close"
                        plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">
        <div id="DataGridRole" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="RoleID"
            sizelist="[10,20,50,100]" pagesize="20" onrowdblclick="ondoubleclick()">
            <div property="columns">
                <div type="indexcolumn" width="15">
                </div>
                <div field="RoleName" width="120" headeralign="center" allowsort="true">
                    角色名称</div>
                <div field="OpRight" width="120" headeralign="center" allowsort="true" renderer="onOpRightRenderer">
                    触发及解除异常权限</div>
                <div field="SignRight" width="120" headeralign="center" allowsort="true" renderer="onSignRightRenderer">
                    签到处理权限</div>
                <div field="FixRight" width="120" headeralign="center" allowsort="true" renderer="onFixRightRenderer">
                    修正异常权限
                </div>
                <div field="Remark" width="250" headeralign="center" allowsort="false">
                    备注
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    mini.parse();
    var grid = mini.get("DataGridRole");
    grid.setUrl("../service/SystemManageHandler.ashx?action=GetRoleList");
    grid.load();

    function add() {
        mini.open({
            url: "SystemManage/RoleInfoForm.aspx",
            title: "新增角色", width: 550, height: 318,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    function ondoubleclick() { edit(); }
    function edit() {
        var rows = grid.getSelected();
        if (rows) {
            mini.open({
                url: "SystemManage/RoleInfoForm.aspx",
                title: "编辑角色", width: 550, height: 318,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", RoleID: rows.RoleID };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
        else {
            mini.alert("请选中一条您需要编辑的记录!");
        }
    }

    function search() {
        var RoleName = mini.get("RoleName").getValue();
        grid.load({ RoleName: RoleName });
    }

    //回车键事件
    function onKeyEnter() {
        search();
    }

    function reset() {
        mini.get("RoleName").setValue("");
    }


    function remove() {
        var rows = grid.getSelected();
        if (rows) {
            $.ajax({
                url: "../service/SystemManageHandler.ashx?action=GetRoleCount&RoleID=" + rows.RoleID,
                success: function (result) {
                    if (result > 0) {
                        mini.alert("有用户正在使用" + rows.RoleName + "该角色，不能被删除！");
                    }
                    else {
                        mini.confirm("您确定删除:" + rows.RoleName + "？", "确定？",
                        function (action) {
                            if (action == "ok") {
                                $.ajax({
                                    url: "../service/SystemManageHandler.ashx?action=RemoveRole&RoleID=" + rows.RoleID,
                                    success: function (text) {
                                        grid.reload();
                                    },
                                    error: function (jqXHR, textStatus, errorThrown) {
                                        alert(jqXHR.responseText);
                                    }
                                });
                            }
                            else {
                                mini.alert("系统默认基础资料不允许删除！");
                            }
                        });
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });



        }
        else {
            mini.alert("请选中一条您需要删除的记录!");
        }
    }
    function onOpRightRenderer(e) {
        if (e.value == 0) { return "<span >不允许</span>"; }
        else if (e.value == 1) { return "<span >允许（指定产线）</span>"; }
        else if (e.value == 2) { return "<span >允许（所有产线）</span>"; }
        else { return ""; }
    }
    function onSignRightRenderer(e) {
        if (e.value == 0) { return "<span >不允许</span>"; }
        else if (e.value == 1) { return "<span >允许</span>"; }
        else { return ""; }
    }

    function onFixRightRenderer(e) {
        if (e.value == 0) { return "<span >不允许</span>"; }
        else if (e.value == 1) { return "<span >允许</span>"; }
        else { return ""; }
    }

    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function close() {
        CloseWindow("close");
    }
</script>
